package com.rsk.dao.extend;


import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author mry
 * 扩展类
 */

@Component
public class SysCompanysExtend {

    public Map<String, Object> selectCourseCategoryByPage(Long companyAttribute, String companyName, Long companyTypeId){
        // 拼接SQL语句
        StringBuilder sql = new StringBuilder("SELECT company_attribute,company_name FROM sys_companys where is_del = 0");

        // 查询需要的参数，先存进Map
        StringBuilder paramSql = new StringBuilder();
        Map<String, Object> paramMap = new HashMap<String, Object>();
        if (companyName != null && !companyName.isEmpty()) {
            paramSql.append(" and company_name like :companyName");
            paramMap.put("companyName", "%" + companyName + "%");
        }
        if (companyAttribute != null) {
            paramSql.append(" and company_attribute like :companyAttribute");
            paramMap.put("companyAttribute", "%" + companyAttribute + "%");
        }
        if (companyTypeId != null){
            paramSql.append("and company_Type_Id like : companyTypeId");
            paramMap.put("companyTypeId","%" + companyTypeId + "%");
        }
        //排序
        StringBuilder orderSql = new StringBuilder();
        orderSql = orderSql.append(" order by sort");

        Map<String, Object> returnMap = new HashMap<String, Object>();
        returnMap.put("sql", sql.append(paramSql).append(orderSql));
        returnMap.put("paramMap", paramMap);
        return returnMap;
    }
}
